import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

const state = {
  httpError: {
    hasError: false,
    status: '',
    statusText: ''
  },
  car_da:'我是熊大',
  openid: '',
  shopCar: [
    // {
    //   id: '12312323', //商品id
    //   count: '', //数量
    //   package: '' //套餐
    // }
  ],
  pageInfo: {
    title: '',
    description: '宏香馨众筹活动'
  },
  loginType: 'wx',
  goodInfo: {},
  urlParams: {
    good_id: "",
    username: "",
    ad: "",
    platform: ""
  },
  kefu_tel: '',
  root_menu_id: ''
};
const mutations = {
  ON_HTTP_ERROR(state, payload) {
    state.httpError = payload
  },
  CHANGE_NAME(state,new_name){

  },
  ADDCARTITEM(state, cartItem) {
    if (state.shopCar.length != 0) {
      state.shopCar.forEach(item => {
        if (item.id == cartItem.id) {
          console.log(123)
          item.count += cartItem.count
          return false;
        } else {
          state.shopCar.push(cartItem)
        }
      })
    } else {
      state.shopCar.push(cartItem)
    }
  },
  SETOPENID(state, openid) {
    state.openid = openid
  },
  SETPAGEINFO(state, pageInfo) {
    state.pageInfo = pageInfo
  },
  SETLOGINTYPE(state, type) {
    state.loginType = type
  },
  SETGOODINFO(state, goodInfo) {
    state.goodInfo = goodInfo
  },
  SETURLPARAMS(state, urlParams ) {
    state.urlParams = urlParams
  },
  SETKEFUTEL(state,tel) {
    state.kefu_tel = tel
  },
  SETROOTMENUID(state,root_menu_id) {
    state.root_menu_id = root_menu_id
  }
};
const getters = {

};

export default new Vuex.Store({
  state,
  mutations,
  getters
});
